package cc.admin.modules.sys.service.impl;

import cc.admin.common.util.oConvertUtils;
import cc.admin.modules.sys.entity.SysRoleReport;
import cc.admin.modules.sys.mapper.SysRoleReportMapper;
import cc.admin.modules.sys.service.ISysRoleReportService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Author: cc-admin
 * @Date:   2023-01-16
 * @Version: V1.0.0
 */
@Service
public class SysRoleReportServiceImpl extends ServiceImpl<SysRoleReportMapper, SysRoleReport> implements ISysRoleReportService {
    @Override
    public void saveRoleReport(String roleId, String reportIds) {
        LambdaQueryWrapper<SysRoleReport> query = new QueryWrapper<SysRoleReport>().lambda().eq(SysRoleReport::getRoleId, roleId);
        this.remove(query);
        List<SysRoleReport> list = new ArrayList<SysRoleReport>();
        String[] arr = reportIds.split(",");
        for (String p : arr) {
            if (oConvertUtils.isNotEmpty(p)) {
                SysRoleReport rolepms = new SysRoleReport(roleId, p);
                list.add(rolepms);
            }
        }
        this.saveBatch(list);
    }

}
